﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Kokomo.PeInspector.Reflection.Disassembly
{
	/// <summary>
	/// Represents a dependency of an MSIL procedure.
	/// </summary>
	/// <remarks>
	/// <see cref="MsilDecompiler.GetDependenciesOf(System.Reflection.MethodBase)"/> provides a list
	/// of dependencies of a method.
	/// </remarks>
	/// <seealso cref="MsilTypeDependency"/>
	/// <seealso cref="MsilFieldDependency"/>
	/// <seealso cref="MsilMethodDependency"/>
	public abstract class MsilDependency
	{
		/// <summary>
		/// Get the offset of the instruction causing the dependency.
		/// </summary>
		public int Offset { get; private set; }
		public Module TargetModule { get; private set; }

		/// <summary>
		/// Initializes a new <see cref="MsilDependency"/>.
		/// </summary>
		/// <param name="offset">The offset of the instruction causing the dependency.</param>
		/// <param name="target">The dependency.</param>
		protected MsilDependency(
			Module targetModule,
			int offset
			)
		{
			if (targetModule == null) throw new ArgumentNullException("targetModule");

			//if (target == null) throw new ArgumentNullException("target");
			//this.Target = target;
			this.Offset = offset;
			this.TargetModule = targetModule;
		}

		public override string ToString()
		{
			//return string.Format("{0:X4]: {1}", this.Offset, this.Target);
			return this.Offset.ToString("X4");
		}
	}
}
